package com.capt_4.equation;

import java.util.Random;

public abstract class Equation {
//public class Equation {
    int leftNumber,rightNumber,result;
    char op = '+';

    public int getLeftNumber() {
        return leftNumber;
    }

    public void setLeftNumber(int leftNumber) {
        this.leftNumber = leftNumber;
    }

    public int getRightNumber() {
        return rightNumber;
    }

    public void setRightNumber(int rightNumber) {
        this.rightNumber = rightNumber;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public char getOp() {
        return op;
    }

    public void setOp(char op) {
        this.op = op;
    }
    
//    输出
    public String toString(){
//        return ""+leftNumber + op + rightNumber+"="+result;
        return ""+leftNumber + op + rightNumber+"=";
    }

    // 生成随机数
    public int generateNumber(int max,int min){
        Random random = new Random();
        return random.nextInt(max-min+1)+min;
    }

    // 判断数据是否符合
    public boolean isBetween(int value,int max,int min){
        return value >= min&&value <= max;
    }

    public boolean isEqual(Equation e){
        if (this.op!=e.getOp()){
            return false;
        } else {
            if (this.getLeftNumber() == e.getLeftNumber() && this
                    .getRightNumber() == e.getRightNumber()){
                return true;
            } else {
                return false;
            }
        }
    }


    //        产生算式(为算式变量赋值)
    public void generateEquattion(char op){
//        System.out.println("产生算式："+op);
        do {
            leftNumber = generateNumber(100,0);
            rightNumber = generateNumber(100,0);
            this.op = op;
//            System.out.println("jjdhhgfgf"+this.op);
//            抽象方法调用
            result = calculate();
//            result = this.leftNumber +this.op+this.rightNumber;
        } while (!isBetween(result,100,0));

    }


//    计算结果 ,抽象方法
    abstract public int calculate();


}
